package com.one.shopping.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.one.shopping.R;
import com.one.shopping.entity.Member;
import com.one.shopping.ui.baseActivity.BaseActivity;

/**
 * @author 柯尊诚
 * @version 1.0
 * @date 创建时间：2016/1/11 23:21
 */
public class MemberDetailActivity extends BaseActivity{

    private TextView cardIdValues;
    private TextView nameValues;
    private TextView phoneValues;
    private TextView scoreValues;
    private TextView moneyValues;
    private Button updateBtn;
    private Member member;

    @Override
    protected int getContentViewId() {
        return R.layout.list_member_detail;
    }

    @Override
    protected void initView() {
        super.initView();
        setTitle("会员详情");
        isVisibleAdd(true);

        cardIdValues = findView(R.id.member_detail_cardid_values_tv);
        nameValues = findView(R.id.member_detail_name_values_tv);
        phoneValues = findView(R.id.member_detail_phone_values_tv);
        scoreValues = findView(R.id.member_detail_score_values_tv);
        moneyValues = findView(R.id.member_detail_money_values_tv);
        updateBtn = findView(R.id.member_update_btn);
    }

    @Override
    protected void initData() {
        super.initData();
        Intent intent = getIntent();
        member = (Member)intent.getSerializableExtra("member");

        cardIdValues.setText(member.getCardId() + "");
        nameValues.setText(member.getUserName());
        phoneValues.setText(member.getPhone());
        scoreValues.setText(member.getScore() + "");
        moneyValues.setText(member.getMoney() + "");
    }

    @Override
    protected void initListener() {
        super.initListener();

        addBtn.setOnClickListener(onClickAddBtnListener);

        updateBtn.setOnClickListener(onClickUpdateBtnListener);
    }

    /**
     * 点击添加按钮
     */
    private View.OnClickListener onClickAddBtnListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            finish();
            Intent intent = new Intent(MemberDetailActivity.this, AddMemberActivity.class);
            startActivity(intent);
        }
    };

    /**
     * 点击更新按钮
     */
    private View.OnClickListener onClickUpdateBtnListener = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            finish();
            Intent intent = new Intent(MemberDetailActivity.this, AddMemberActivity.class);
            Bundle bundle = new Bundle();
            bundle.putSerializable("member", member);
            intent.putExtras(bundle);
            startActivity(intent);
        }
    };
}
